package com.netease.xone.adapter;

import protocol.meta.User;
import protocol.meta.UserDynamic;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.netease.framework.widget.LinkedListAdapter;
import com.netease.xone.R;
import com.netease.xone.itemview.RenderDynamicView;


public class DynamicAdapter extends LinkedListAdapter<UserDynamic> {

    private Context mContext;
    private boolean mHasMore;

    public DynamicAdapter(Context context ) {
        mContext = context;
        mHasMore = true;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(mContext, R.layout.view_dynamic_list_item, null);
            RenderDynamicView render = new RenderDynamicView(convertView);
            convertView.setTag(render);
        }
        RenderDynamicView render = (RenderDynamicView)convertView.getTag();
        boolean sameWithBefore = false;
        if(position > 0){
            User userBefore  = getItem(position - 1).userVO;
            User userNow = getItem(position).userVO;
            if(userBefore != null && userNow != null && userBefore.userId.equals(userNow.userId)){
                sameWithBefore = true;
            }
        }
        boolean isTheLast = (position == getCount() - 1) && !mHasMore;
        render.renderView(mContext, getItem(position), sameWithBefore, isTheLast);
        return convertView;
    }

    public void setHasMore(boolean hasMore){
        mHasMore = hasMore;
    }


}
